home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3703 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  67 lines

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Template help...
  5. Date: Thu, 25 Jan 1996 17:51:03 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4e8ftc$lm6@news.halcyon.com>
  8. References: <31039FBD.167EB0E7@uci.edu>
  9. NNTP-Posting-Host: blv-pm11-ip18.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Would it be repugnant to use two types in your template, one for the
  13. block type, one for the search key type?  You could, conceivably,
  14. define operator< and operator== for several search keys in struct
  15. a_block and create different a_temps to search them with the different
  16. keys.
  17.  
  18. template <class element, class key>
  19. struct temp {
  20.     ...
  21. }
  22. typedef temp<a,char*> a_temp
  23.  
  24.                         --Norm 
  25.  
  26. Doug Semler <drsemler@uci.edu> wrote:
  27.  
  28. >Question about templating:
  29.  
  30. >I have a template
  31.  
  32. >template
  33. >< class element >
  34. >struct temp {
  35. >    ...   // elements in template, ctors, etc. implementing linked list
  36. >};
  37.  
  38. >and define my types such:
  39.  
  40. >typedef struct a_block *a;
  41. >typedef <a> a_temp;
  42. >typedef a_temp a_list;
  43.  
  44. >typedef struct b_block *b;
  45. >typedef <b> b_temp;
  46. >typedef b_temp b_list;
  47.  
  48. >a_list A;
  49. >b_list B;
  50.  
  51. >My problem is this...I want to find elements from list A based on a 
  52. >character string, and list B based on an integer.  The code is the
  53. >same (traverse list until found) and I would like to be able to say
  54. >A->find_element(char *id);  or 
  55. >B->find_element(int i);
  56.  
  57. >(I have overloaded == function for char * types BTW)
  58. >Is it possible?
  59.  
  60. >-- 
  61. >Doug Semler                      | drsemler@uci.edu
  62. >University of California, Irvine | Send all flames to /dev/null
  63. >Information and Computer Science | Of course these are *MY* opinions
  64. >http://www.ics.uci.edu/~dsemler  | When in doubt, RTFM!
  65.  
  66.  
  67.